var timeout_json = function(data, $window) {
	if(data.returnCode == 999994) {
		var ss = 3;
		layer.msg(data.returnMessage + "！<strong class='Ajax_Out'>" + ss + "</strong> 秒后前往登录页", 50, -1);
		var picInt = setInterval(function() {
			if(ss >= 1) {
				ss = ss - 1;
				$('.Ajax_Out').text(ss);
			} else {
				clearInterval(picInt);
				try {
					$window.parent.location.href = data.returnData;
					$window.location.href = data.returnData;
				} catch(e) {
					log('timeout!')
				}
			}
		}, 1000);
		return false;
	}
}

var getSs=function(reStr,v){
	if(reStr&&reStr!="None"){
		var cls=reStr.split(',');
		for(ii=0;ii<cls.length;ii++){
			if(v==cls[ii]){
				return false || ii;
			}
		}
	}
}

var changeCheck = function(e, isCheck) {
	var _ = $(e);
	if(isCheck == 0 || isCheck == 1) {
		if(isCheck == 0) {
			_.removeClass('checked');
		} else {
			_.addClass('checked');
		}
	} else {
		if(_.attr('class').search('checked') > -1) {
			_.removeClass('checked');
		} else {
			_.addClass('checked');
		}
	}
}

var app = angular.module("newNextApp", []);
	
app.config(function($httpProvider) {
	$httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';
	$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
	$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
});

app.controller('editCtrl', function($scope, $http, $window, $timeout) {
	var vm = $scope.vm = {
		ifm_name: null,
		ifm_pushed: 0,
		ifm_type: null,
		ifm_note: null,
		ifm_getChannel: null,
		ifm_notChannel: null,
		ifm_getWechatId: null,
		ifm_notWechatId: null,
		ifm_getBloggerId: null,
		ifm_notBloggerId: null,
		ifm_getBbsName: null,
		ifm_notBbsName: null,
		ifm_getKeyword: "",
		ifm_notKeyword: "",
		ifm_isdelete: 0,
		ifm_matePattern: null,
		ifm_filterPattern: null,
		
	};
	
	$scope.domAjax = function(e) {
		var isPublished = $("#publish").attr("disabled");
		if(isPublished == "disabled"){
			return false;
		}
		
		if(e === "release") {	
			function ifmParams(rscType,allSelectType,partSelectType,allFilterType,partFilterType,ifmGetType,ifmNotType,ifmGetTypes,ifmNotTypes){
				if(rscType.val()==allSelectType){
					$scope.vm[ifmGetType] = "All";
					$scope.vm[ifmNotType] = null;
				}
				if(rscType.val()==partSelectType){
					if (window[ifmGetTypes]&&window[ifmGetTypes].substr(0,1)==','){window[ifmGetTypes] = window[ifmGetTypes].substr(1);}
					$scope.vm[ifmGetType] = window[ifmGetTypes];
					$scope.vm[ifmNotType] = null;
				}
				if(rscType.val()==allFilterType){
					$scope.vm[ifmNotType] = "All";
					$scope.vm[ifmGetType] = null;
				}
				if(rscType.val()==partFilterType){
					if (window[ifmNotTypes]&&window[ifmNotTypes].substr(0,1)==','){window[ifmNotTypes] = window[ifmNotTypes].substr(1);}
					$scope.vm[ifmNotType] = window[ifmNotTypes];
					$scope.vm[ifmGetType] = null;
				}
			}
			//频道、微信、微博、论坛
			ifmParams($("#rscNews"),"allSelectNews","partSelectNews","allFilterNews","partFilterNews","ifm_getChannel","ifm_notChannel","getChannels","notChannels");
			ifmParams($("#rscWeChat"),"allSelectWeChat","partSelectWeChat","allFilterWeChat","partFilterWeChat","ifm_getWechatId","ifm_notWechatId","getWechatIds","notWechatIds");
			ifmParams($("#rscWeibo"),"allSelectWeibo","partSelectWeibo","allFilterWeibo","partFilterWeibo","ifm_getBloggerId","ifm_notBloggerId","getBloggerIds","notBloggerIds");
			ifmParams($("#rscBBS"),"allSelectBBS","partSelectBBS","allFilterBBS","partFilterBBS","ifm_getBbsName","ifm_notBbsName","getBbsNames","notBbsNames");

			//提交的匹配关键词-匹配（标题、正文）参数
			if(($("#match_title").attr("class").search("checked")>-1)&&($("#match_body").attr("class").search("checked")>-1)){
				$scope.vm.ifm_matePattern="title|content";
			}else if(($("#match_title").attr("class").search("checked")>-1)&&($("#match_body").attr("class").search("checked")==-1)){
				$scope.vm.ifm_matePattern="title";
			}else if(($("#match_title").attr("class").search("checked")==-1)&&($("#match_body").attr("class").search("checked")>-1)){
				$scope.vm.ifm_matePattern="content";
			}else{
				$scope.vm.ifm_matePattern=null;
			}
			//提交的过滤关键词-匹配（标题、正文）参数
			if(($("#match_title2").attr("class").search("checked")>-1)&&($("#match_body2").attr("class").search("checked")>-1)){
				$scope.vm.ifm_filterPattern="title|content";
			}else if(($("#match_title2").attr("class").search("checked")>-1)&&($("#match_body2").attr("class").search("checked")==-1)){
				$scope.vm.ifm_filterPattern="title";
			}else if(($("#match_title2").attr("class").search("checked")==-1)&&($("#match_body2").attr("class").search("checked")>-1)){
				$scope.vm.ifm_filterPattern="content";
			}else{
				$scope.vm.ifm_filterPattern=null;
			}
			
			var params = {
				ifm_id: null,	
				ifm_name: $("#ifm_name").val(),
				ifm_pushed: $("#ifm_pushed").val(),
				ifm_type: $("#ifm_type").val(),
				ifm_note: $("#ifm_note").val(),
				groupId: $("#ifm_groupId").val(),
				ifm_category: $("#ifm_category").val(),
				ifm_categoryName: $("#ifm_categoryName").val(),
				
				ifm_getChannel: $scope.vm.ifm_getChannel,
				ifm_notChannel: $scope.vm.ifm_notChannel,
				ifm_getWechatId: $scope.vm.ifm_getWechatId,
				ifm_notWechatId: $scope.vm.ifm_notWechatId,
				ifm_getBloggerId: $scope.vm.ifm_getBloggerId,
				ifm_notBloggerId: $scope.vm.ifm_notBloggerId,
				ifm_getBbsName: $scope.vm.ifm_getBbsName,
				ifm_notBbsName: $scope.vm.ifm_notBbsName,
				ifm_getKeyword: $scope.vm.ifm_getKeyword,
				ifm_notKeyword: $scope.vm.ifm_notKeyword,
				ifm_isdelete: $scope.vm.ifm_isdelete,
				ifm_matePattern: $scope.vm.ifm_matePattern,
				ifm_filterPattern: $scope.vm.ifm_filterPattern

			};
			
			if(params.ifm_getKeyword==""){
				params.ifm_getKeyword="None";
			}
			if(params.ifm_notKeyword==""){
				params.ifm_notKeyword="None";
			}
        	//验证关键词的特殊字符
			var strReg = "^[\\u4e00-\\u9fa5a-zA-Z0-9+|()\\s\\\\]+$";
			var re = new RegExp(strReg);
			if(params.ifm_getKeyword!=undefined&&!re.test($.trim(params.ifm_getKeyword))) {
				layer.msg("匹配关键词含有非法字符",2,-1);
				return false;
			}else if(params.ifm_notKeyword!=undefined&&!re.test($.trim(params.ifm_notKeyword))) {
				layer.msg("过滤关键词含有非法字符",2,-1);
				return false;
			}
			if(params.ifm_getKeyword=="None"&&(vm.ifm_matePattern=="title"||vm.ifm_matePattern=="title|content"||vm.ifm_matePattern=="content")){
				layer.msg("请输入匹配关键词,或取消相应匹配标题或正文",3,-1);
				return false;
			}
			if(params.ifm_notKeyword=="None"&&(vm.ifm_filterPattern=="title"||vm.ifm_filterPattern=="title|content"||vm.ifm_filterPattern=="content")){
				layer.msg("请输入过滤关键词,或取消相应匹配标题或正文",3,-1);
				return false;
			}
			if(params.ifm_getKeyword!="None"&&(vm.ifm_matePattern==null)){
				layer.msg("请选择匹配关键词的匹配标题或正文",3,-1);
				return false;
			}
			if(params.ifm_notKeyword!="None"&&(vm.ifm_filterPattern==null)){
				layer.msg("请选择过滤关键词的匹配标题或正文",3,-1);
				return false;
			}
			
			if(params.ifm_getKeyword!=undefined&&params.ifm_notKeyword!=undefined){
				if(params.ifm_getChannel==null && params.ifm_notChannel==null &&
					params.ifm_getWechatId==null && params.ifm_notWechatId==null &&
					params.ifm_getBloggerId==null && params.ifm_notBloggerId==null &&
					params.ifm_getBbsName==null && params.ifm_notBbsName==null ){
					layer.msg("频道、微信号、微博号、论坛等资源至少必填一项！",3,-1);
					return false;
				}
				$.ajax({
					type: "POST",
					url: basePath +'iformation/addIformation.do',
					data: params,
					error: function(request) {
						layer.msg("操作失败，请刷新重试！", 2, -1);
					},
					success: function(data) {
						var j = timeout_json(data, $window);
						if(j == false) {
							return false;
						}
						if(data.returnCode == 10000) {
							layer.msg(data.returnMessage, 1, 10);
							//保存iframe窗口后，不跳转页面
							var t = setTimeout(function(){
								window.parent.$(".dtab").find('#jsgo a.cur').trigger('click');
								window.parent.layer.closeAll();
							},1000);
						} else {
							layer.msg(data.returnMessage, 2, -1);
							return false;
						}
					}
				});
			}
		}
	};
	$scope.cancel = function(e) {
		window.parent.layer.closeAll();
	}
	
	//匹配过滤前的勾选框
	$scope.doCheckChange = function(e, isCheck) {
		changeCheck(e, isCheck);
	}
	
	//初始化数据
	$scope.initData = function(e) {
		var isP_title = 0;
		var isP_content = 0;
		var isF_title = 0;
		var isF_content =0;
		//匹配标题
		if(vm.ifm_matePattern=="title"||vm.ifm_matePattern=="title|content") {
			isP_title = 1;
		}
		$scope.doCheckChange($("#match_title"), isP_title);
		//匹配正文
		if(vm.ifm_matePattern=="content"||vm.ifm_matePattern=="title|content") {
			isP_content = 1;
		}
		$scope.doCheckChange($("#match_body"), isP_content);
		
		//过滤标题
		if(vm.ifm_filterPattern=="title"||vm.ifm_filterPattern=="title|content") {
			isF_title = 1;
		}
		$scope.doCheckChange($("#match_title2"), isF_title);
		//过滤正文
		if(vm.ifm_filterPattern=="content"||vm.ifm_filterPattern=="title|content") {
			isF_content = 1;
		}
		$scope.doCheckChange($("#match_body2"), isF_content);
	
		if($("#rscNews").val()=="partSelectNews"){
			$("#p_newsDiv").css("display","block");
		}else if($("#rscNews").val()=="partFilterNews"){
			$("#f_newsDiv").css("display","block");
		}else if($("#rscWeChat").val()=="partSelectWeChat"){
			$("#p_wechatDiv").css("display","block");
		}else if($("#rscWeChat").val()=="partFilterWeChat"){
			$("#f_wechatDiv").css("display","block");
		}else if($("#rscWeibo").val()=="partSelectWeibo"){
			$("#p_weiboDiv").css("display","block");
		}else if($("#rscWeibo").val()=="partFilterWeibo"){
			$("#f_weiboDiv").css("display","block");
		}else if($("#rscBBS").val()=="partSelectBBS"){
			$("#p_webbsDiv").css("display","block");
		}else if($("#rscBBS").val()=="partFilterBBS"){
			$("#f_webbsDiv").css("display","block");
		}
		
		function ifmInitDrop(ifmGetType,ifmNotType,allSelectTypeObj,partSelectTypeObj,allFilterTypeObj,partFilterTypeObj){
			if(vm[ifmGetType] != null && vm[ifmGetType] != undefined && vm[ifmGetType] != ""||vm[ifmNotType] != null && vm[ifmNotType] != undefined && vm[ifmNotType] != "") {
				var ifmGetTypeStr = vm[ifmGetType];
				var ifmNotTypeStr = vm[ifmNotType];
				if(ifmGetTypeStr=="All"){
					allSelectTypeObj.trigger('click');
					$('.ui_s_bk').css('display','none');
				}else if((ifmGetTypeStr!="All")&&(ifmGetTypeStr!="None")){
					partSelectTypeObj.trigger('click');
					$('.ui_s_bk').css('display','none');
				}else if(ifmNotTypeStr=="All"){
					allFilterTypeObj.trigger('click');
					$('.ui_s_bk').css('display','none');
				}else if((ifmNotTypeStr!="All")&&(ifmNotTypeStr!="None")){
					partFilterTypeObj.trigger('click');
					$('.ui_s_bk').css('display','none');
				}
			}
		}
		//初始下拉框的选项内容展示
		ifmInitDrop("ifm_getChannel","ifm_notChannel",$('#allSelectNewsSpan'),$('#partSelectNewsSpan'),$('#allFilterNewsSpan'),$('#partFilterNewsSpan'));
		ifmInitDrop("ifm_getWechatId","ifm_notWechatId",$('#allSelectWeChatSpan'),$('#partSelectWeChatSpan'),$('#allFilterWeChatSpan'),$('#partFilterWeChatSpan'));
		ifmInitDrop("ifm_getBloggerId","ifm_notBloggerId",$('#allSelectWeiboSpan'),$('#partSelectWeiboSpan'),$('#allFilterWeiboSpan'),$('#partFilterWeiboSpan'));
		ifmInitDrop("ifm_getBbsName","ifm_notBbsName",$('#allSelectBBSSpan'),$('#partSelectBBSSpan'),$('#allFilterBBSSpan'),$('#partFilterBBSSpan'));
	}

});

/**
 * 文本框根据输入内容自适应高度
 * @param   {HTMLElement} 	 输入框元素
 * @param   {Number}         设置光标与输入框保持的距离(默认0)
 * @param   {Number}         设置最大高度(可选)
 */
var autoTextarea = function (elem, extra, maxHeight) {
	extra = extra || 0;
    var isFirefox = !!document.getBoxObjectFor || 'mozInnerScreenX' in window,
     	isOpera = !!window.opera && !!window.opera.toString().indexOf('Opera'),
        addEvent = function (type, callback) {
        	elem.addEventListener ?
                elem.addEventListener(type, callback, false) :
                elem.attachEvent('on' + type, callback);
    },
    getStyle = elem.currentStyle ? function (name) {
        var val = elem.currentStyle[name];
        if (name === 'height' && val.search(/px/i) !== 1) {
            var rect = elem.getBoundingClientRect();
            return rect.bottom - rect.top -
                   parseFloat(getStyle('paddingTop')) -
                   parseFloat(getStyle('paddingBottom')) + 'px';        
        };
            return val;
    } : function (name) {
                    return getComputedStyle(elem, null)[name];
    },
    minHeight = parseFloat(getStyle('height'));
    elem.style.resize = 'none';
    var change = function () {
        var scrollTop, height,
                padding = 0,
                style = elem.style;
        if (elem._length === elem.value.length) return;
        elem._length = elem.value.length;
        if (!isFirefox && !isOpera) {
                padding = parseInt(getStyle('paddingTop')) + parseInt(getStyle('paddingBottom'));
        };
        scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
        elem.style.height = minHeight + 'px';
        if (elem.scrollHeight > minHeight) {
            if (maxHeight && elem.scrollHeight > maxHeight) {
                height = maxHeight - padding;
                style.overflowY = 'auto';
            } else {
                height = elem.scrollHeight - padding;
                style.overflowY = 'hidden';
            };
            style.height = height + extra + 'px';
            scrollTop += parseInt(style.height) - elem.currHeight;
            document.body.scrollTop = scrollTop;
            document.documentElement.scrollTop = scrollTop;
            elem.currHeight = parseInt(style.height);
        };
    };
    addEvent('propertychange', change);
    addEvent('input', change);
    addEvent('focus', change);
    change();
};
var kwdText = document.getElementById("kwd");
var fwdText = document.getElementById("fwd");
autoTextarea(kwdText);
autoTextarea(fwdText);

$(function() {
	laydate.skin('molv');
	$('.ui_select').each(function() {
		var _ = $(this),
			_a = _.find('.ui_s_t'),
			_c = _.find('.ui_s_bk'),
			_ca = _c.find('a');
		_a.live('click', function() {
			_c.slideToggle(200, "easeInSine");
		});
		_ca.live('click', function() {
			$(this).addClass('cur').siblings().removeClass('cur');
			_a.text($(this).text());
//			根据不同的选项，展现不同的选择标签按钮
			$(this).parent().siblings("input").val($(this).attr("type"));
			_c.slideToggle(200, "easeInSine");
			var selectTag = $(this).parent().siblings("input").val();
			if(selectTag=="partSelectNews"){
				$("#f_newsDiv").css("display","none");
				$("#p_newsDiv").css("display","block");
			}else if(selectTag=="partFilterNews"){
				$("#p_newsDiv").css("display","none");
				$("#f_newsDiv").css("display","block");
			}else if(selectTag=="partSelectWeChat"){
				$("#f_wechatDiv").css("display","none");
				$("#p_wechatDiv").css("display","block");
			}else if(selectTag=="partFilterWeChat"){
				$("#p_wechatDiv").css("display","none");
				$("#f_wechatDiv").css("display","block");
			}else if(selectTag=="partSelectWeibo"){
				$("#f_weiboDiv").css("display","none");
				$("#p_weiboDiv").css("display","block");
			}else if(selectTag=="partFilterWeibo"){
				$("#p_weiboDiv").css("display","none");
				$("#f_weiboDiv").css("display","block");
			}else if(selectTag=="partSelectBBS"){
				$("#f_bbsDiv").css("display","none");
				$("#p_bbsDiv").css("display","block");
			}else if(selectTag=="partFilterBBS"){
				$("#p_bbsDiv").css("display","none");
				$("#f_bbsDiv").css("display","block");
			}else{
				$(this).parent().parent().siblings("div").css("display","none");
			}
		});
		_c.live('mouseleave', function() {
			_c.stop(false, true).slideUp(200, "easeInSine");
		});
	});

	$('.ui_select').live('keyup', function(e) {
		var _ = $(this),
			b = _.find('.ui_s_bk'),
			di = 27;
		_.focus();
		e = e || window.event;
		var indx = b.find('a.cur').index() || 0;
		if(e.keyCode == 40) {
			var aindx = indx + 1,
				sct;
			if(rindx >= b.find('a').length) {
				rindx = b.find('a').length;
			}
			b.find('a').eq(aindx).addClass('cur').siblings('a').removeClass('cur');
			sct = aindx * di > 180 ? aindx * di - 80 : 0;
			b.scrollTop(sct);
		} else if(e.keyCode == 38) {
			var rindx = indx - 1,
				sct;
			sct = aindx * di > 100 ? aindx * di : 0;
			if(rindx <= 0) {
				rindx = 0;
			}
			b.find('a').eq(rindx).addClass('cur').siblings('a').removeClass('cur');
			sct = rindx * di > 180 ? rindx * di - 80 : 0;
			b.scrollTop(sct);
		} else if(e.keyCode == 13) {
			b.find('a.cur').trigger('click');
			_.blur();
			_.find('.ui_s_t').blur();
		}
		return false;
	});
	//open edit Layer
	var editExaDataLayer = null;
	var queryType;
//	var pagePlugn={}
	$('.editExaDataBtn').live('click', function() {
		var editExaDataLayer = $.layer({
			type: 1,
			title: false,
			area: ['900', '100%'],
			border: [0], //去掉默认边框
			shade: [0.3, '#000'], //去掉遮罩
			closeBtn: [0, false], //去掉默认关闭按钮
			fadeIn: 500,
			move: "#editExaData_tile",
			page: {
				dom: '#editExaDataLayer'
			}
		});
		$(this).addClass("cL");
		//自设关闭
		$('#editExaDataLayer > .closeBtn,#editExaDataLayer .cancelLayer').live('click', function() {
			layer.close(editExaDataLayer);
			curPage=1;
			$('.editExaDataBtn').removeClass("cL");
			$('#checkQueryInput').val('');
		});
	});

	var edit = {
		"qRscList": function(_this, rscArr, queryValue, pIndex, numList, selectJson) {
			var queryUrl = {
				p_newsType: "channel/queryChannelByType.do",f_newsType: "channel/queryChannelByType.do",
				p_wechatType: "weixin/queryWeixinByType.do",f_wechatType: "weixin/queryWeixinByType.do",
				p_weiboType: "microuser/queryMicroserByType.do",f_weiboType: "microuser/queryMicroserByType.do",
				p_bbsType: "channel/queryChannelByType.do",f_bbsType: "channel/queryChannelByType.do"
			};
			if(isNaN(numList)){
				numList=5000;
			}
			
			var queryParams = {
				p_newsType: {
					ifm_id:null,
					channel_type:"News",
					pageIndex: pIndex,
					pageSize: numList,
					channel_name:selectJson.channel_name,
					types:queryType
				},
				f_newsType: {
					ifm_id:null,
					channel_type:"News",
					pageIndex: pIndex,
					pageSize: numList,
					channel_name:selectJson.channel_name,
					types:queryType
				},
				p_wechatType: {
					ifm_id:null,
					pageIndex: pIndex,
					pageSize: numList,
					weixin_name:selectJson.weixin_name,
					types:queryType
				},
				f_wechatType: {
					ifm_id:null,
					pageIndex: pIndex,
					pageSize: numList,
					weixin_name:selectJson.weixin_name,
					types:queryType
				},
				p_weiboType: {
					ifm_id:null,
					pageIndex: pIndex,
					pageSize: numList,
					microuser_blogger:selectJson.microuser_blogger,
					types:queryType
				},
				f_weiboType: {
					ifm_id:null,
					pageIndex: pIndex,
					pageSize: numList,
					microuser_blogger:selectJson.microuser_blogger,
					types:queryType
				},
				p_bbsType: {
					ifm_id:null,
					channel_type:"BBS",
					pageIndex: pIndex,
					pageSize: numList,
					channel_name:selectJson.channel_name,
					types:queryType
				},
				f_bbsType: {
					ifm_id:null,
					channel_type:"BBS",
					pageIndex: pIndex,
					pageSize: numList,
					channel_name:selectJson.channel_name,
					types:queryType
				}
			};
			var showTypeParams = {
				p_newsType: {
					name: "channel_name",
					id:"channel_id"
				},
				f_newsType: {
					name: "channel_name",
					id:"channel_id"
				},
				p_wechatType: {
					name: "weixin_name",
					id:"weixinuser_Id"
				},
				f_wechatType: {
					name: "weixin_name",
					id:"weixinuser_Id"
				},
				p_weiboType: {
					name: "microuser_blogger",
					id:"microuser_bloggerId"
				},
				f_weiboType: {
					name: "microuser_blogger",
					id:"microuser_bloggerId"
				},
				p_bbsType: {
					name: "channel_name",
					id:"channel_id"
				},
				f_bbsType: {
					name: "channel_name",
					id:"channel_id"
				}
			};
			var resStrParams = {
				p_newsType: {
					content: window.getChannels
				},
				f_newsType: {
					content: window.notChannels
				},
				p_wechatType: {
					content: window.getWechatIds
				},
				f_wechatType: {
					content: window.notWechatIds
				},
				p_weiboType: {
					content: window.getBloggerIds
				},
				f_weiboType: {
					content: window.notBloggerIds
				},
				p_bbsType: {
					content: window.getBbsNames
				},
				f_bbsType: {
					content: window.notBbsNames
				}
			};
			var _obj = $(".ktab");
			$.ajax({
				type: "POST",
				url: basePath + queryUrl[eval('queryType')],
				data: queryParams[eval('queryType')],
				success: function(data) {
					if(data.returnCode == 10000) {
						var s2 = data.returnData.length;
						var showTypeParamName = showTypeParams[eval('queryType')].name;
						var showTypeParamId = showTypeParams[eval('queryType')].id;
						var resStrParam = resStrParams[eval('queryType')].content;
						if(s2 > 0) {
							var htmls = "";
							var checkedHtmls = "";
							var htmlEnd="";
							for(var i = 0; i < s2; i++) {
								var checkedBtn = "";
								var checked = "";
								var channelName2 = data.returnData[i][eval("showTypeParamName")];
								var channelId2 = data.returnData[i][eval("showTypeParamId")];
								var checkeddefault = "";
								var num = rscArr.length;
								//频道、论坛
								if(queryType.indexOf("news")>0||queryType.indexOf("bbs")>0){
									for(var nn = 0; nn < num; nn++) {
										if(getSs(resStrParam,channelName2)||getSs(resStrParam,channelName2)==0) {
											checkedBtn = "true";
											checked = "checked";
											checkeddefault = "true";
											break;
										} else {
											checkedBtn = "false";
											checkeddefault = "false";
											checked = "";
										}
									}
								}

								//微信号、微博号
								if(queryType.indexOf("wechat")>0||queryType.indexOf("weibo")>0){
									for(var nn = 0; nn < num; nn++) {
										if(getSs(resStrParam,channelId2)||getSs(resStrParam,channelId2)==0) {
											checkedBtn = "true";
											checked = "checked";
											checkeddefault = "true";
											break;
										} else {
											checkedBtn = "false";
											checkeddefault = "false";
											checked = "";
										}
									}
								}
							
//								if(getSs(channelName2)) {
								checkedHtmls += "<div class='infoLlist w440 fl' title='" + data.returnData[i][eval("showTypeParamName")] + "'><span class='ui_checkbox " + checked + "' t-name= '" + data.returnData[i][eval("showTypeParamName")] + "' t-id= '" + data.returnData[i][eval("showTypeParamId")] +  "' checkedBtn='" + checkedBtn + "' checkeddefault='" + checkeddefault + "'></span> <font>" + data.returnData[i][eval("showTypeParamName")] + "</font></div>";
//								} else {
//									选中与未选中分开展示
//									htmls += "<div class='infoLlist fl w300' title='" + data.returnData[i][eval("showTypeParamName")] + "'><span class='ui_checkbox " + checked + "' t-name= '" + data.returnData[i][eval("showTypeParamName")] + "' checkedBtn='" + checkedBtn + "' checkeddefault='" + checkeddefault + "'></span> <font>" + data.returnData[i][eval("showTypeParamName")] + "</font></div>";
//								}
							}
							var strPage = "<div class='pages' style='position:relative;top:6px;'><div class='ui_page' id='pageArea'></div></div>";
							 
//							$("#checkQueryInput").val("");
							$("#editExaData_tile").text(_this.attr("title") + "列表");
							if(_this.attr("title")=="选择频道"){
								$("#hiddenType").val("");
								$("#hiddenType").val("partSelectNews");
							}else if(_this.attr("title")=="过滤频道"){
								$("#hiddenType").val("");
								$("#hiddenType").val("partFilterNews");
							}else if(_this.attr("title")=="选择微信号"){
								$("#hiddenType").val("");
								$("#hiddenType").val("partSelectWeChat");
							}else if(_this.attr("title")=="过滤微信号"){
								$("#hiddenType").val("");
								$("#hiddenType").val("partFilterWeChat");
							}else if(_this.attr("title")=="选择微博号"){
								$("#hiddenType").val("");
								$("#hiddenType").val("partSelectWeibo");
							}else if(_this.attr("title")=="过滤微博号"){
								$("#hiddenType").val("");
								$("#hiddenType").val("partFilterWeibo");
							}else if(_this.attr("title")=="选择论坛"){
								$("#hiddenType").val("");
								$("#hiddenType").val("partSelectBBS");
							}else if(_this.attr("title")=="过滤论坛"){
								$("#hiddenType").val("");
								$("#hiddenType").val("partFilterBBS");
							}
						
							$("#editExaData_listName").text(_this.attr("title").substring(2) + "名称");
							_obj.html(checkedHtmls + htmls + "<div class='clear'></div>");
							$(".pageDiv").html(strPage);
							paging.loadPage(data);
							checkTrueFalse();
						}
						if(s2 < 1) {
							_obj.html("<br><bR><p align='center'>很遗憾，没有查询到相关的数据！</p><br><bR>");
						}
					} else if(data.returnCode == 999994) {
						setUserTimeout(data);
					} else {
						layer.msg(data.returnMessage, 2, -1);
					}
				},
				error: function(message) {
					layer.msg("操作失败，请重试！", 2, -1);
				},
				beforeSend: function() {
					var imgGif = "<p class='loadingGif'></p>";
					_obj.html(imgGif);
				}
			});
		}
	}

	$(".infoLlist .ui_checkbox").live("click", function() {
		var selectTags = $("#hiddenType").val();
		if($(this).attr("checkedBtn") == "true") {
			$(this).attr("checkedBtn", "false");
			$(this).removeClass("checked");
			
			function selectTagFunc(selectTag,selectType,objCur){
				if(selectTags==selectTag){
					if(selectType.indexOf("Ids") > 0){
						var qc=getSs(window[selectType],objCur.attr("t-id"));
					}else{
						var qc=getSs(window[selectType],objCur.attr("t-name"));
					}
					if(qc||qc==0){debugger;
						var typeArr=window[selectType].split(',');
						typeArr.splice(qc,1);
						window[selectType]=typeArr.join(',');
					}
				}
			}
			selectTagFunc("partSelectNews","getChannels",$(this));
			selectTagFunc("partFilterNews","notChannels",$(this));
			selectTagFunc("partSelectWeChat","getWechatIds",$(this));
			selectTagFunc("partFilterWeChat","notWechatIds",$(this));
			selectTagFunc("partSelectWeibo","getBloggerIds",$(this));
			selectTagFunc("partFilterWeibo","notBloggerIds",$(this));
			selectTagFunc("partSelectBBS","getBbsNames",$(this));
			selectTagFunc("partFilterBBS","notBbsNames",$(this));
		} else {
			$(this).attr("checkedBtn", "true");
			$(this).addClass("checked");
			
			function selectTagsFunc(selectTag,selectType,objCur){
				if(selectTags==selectTag){
					if(selectType.indexOf("Ids")>0){
						var qc=getSs(window[selectType],objCur.attr("t-id"));
					}else{
						var qc=getSs(window[selectType],objCur.attr("t-name"));
					}
					if(!qc){
						if(window[selectType]=="All"||window[selectType]==undefined){
							window[selectType]="";
						}
						if(selectType.indexOf("Ids")>0){
							window[selectType] += (window[selectType]=="") ? objCur.attr("t-id") : (','+objCur.attr("t-id"));
						}else{
							window[selectType] += (window[selectType]=="") ? objCur.attr("t-name") : (','+objCur.attr("t-name"));
						}
					}
				}
			}
			selectTagsFunc("partSelectNews","getChannels",$(this));
			selectTagsFunc("partFilterNews","notChannels",$(this));
			selectTagsFunc("partSelectWeChat","getWechatIds",$(this));
			selectTagsFunc("partFilterWeChat","notWechatIds",$(this));
			selectTagsFunc("partSelectWeibo","getBloggerIds",$(this));
			selectTagsFunc("partFilterWeibo","notBloggerIds",$(this));
			selectTagsFunc("partSelectBBS","getBbsNames",$(this));
			selectTagsFunc("partFilterBBS","notBbsNames",$(this));
		}
	});
	$(".editExaDataBtn").live("click", function() {
//		var rscArr =  $(this).attr("ids").split(",");
		var rscArr =  $(this).parent().prev().text().split(",");
		queryType = $(this).attr('type');
		var params={};
		subPage=0;
		numList=10;
		edit.qRscList($(this), rscArr, params, 1, numList, "");
	});
		
	//全选
	$(".selectAllAreaGoGo .allSel").live("click", function() {
		var checkedbtn = $(this).attr("checkedbtn");
		var selectTags = $("#hiddenType").val();
		var len = $(".infoLlist .ui_checkbox").length;
		//判断在点击全选按钮之前，列表中是否存在已勾选的状态
		for(var ii=0;ii<len;ii++){
			if($(".infoLlist .ui_checkbox").eq(ii).attr("checkedbtn")=="true"){
				$(".infoLlist .ui_checkbox").eq(ii).attr("data-select","true");
			}else{
				$(".infoLlist .ui_checkbox").eq(ii).removeAttr("data-select");
			}
		}
		if(checkedbtn == "false") {
			$(".infoLlist .ui_checkbox,.allSel").addClass("checked").attr("checkedbtn", "true");
			
			function allSelectFunc(selectTag,selectType){
				if(selectTags==selectTag){
//					window[selectType]="";
					for(var i=0;i<len;i++){
						if(selectType.indexOf("Ids")>0){
							if($(".infoLlist .ui_checkbox").eq(i).attr("data-select")=="true"){
								var	nn="";
							}else{
								var nn= $(".infoLlist .ui_checkbox").eq(i).attr("t-id");
							}
						}else{
							if($(".infoLlist .ui_checkbox").eq(i).attr("data-select")=="true"){
								var nn="";
							}else{
								var nn= $(".infoLlist .ui_checkbox").eq(i).attr("t-name");
							}
						}
						var qc=getSs(window[selectType],nn);
						if(!qc){
							if(window[selectType]=="All"||window[selectType]==undefined){
								window[selectType]="";
							}
							window[selectType]+=(nn!="" ? (',' + nn) : nn);
						}
					}
				}
			}
			allSelectFunc("partSelectNews","getChannels");
			allSelectFunc("partFilterNews","notChannels");
			allSelectFunc("partSelectWeChat","getWechatIds");
			allSelectFunc("partFilterWeChat","notWechatIds");
			allSelectFunc("partSelectWeibo","getBloggerIds");
			allSelectFunc("partFilterWeibo","notBloggerIds");
			allSelectFunc("partSelectBBS","getBbsNames");
			allSelectFunc("partFilterBBS","notBbsNames");
	
		} else {
			$(".infoLlist .ui_checkbox,.allSel").removeClass("checked").attr("checkedbtn", "false");
			
			function allSelectsFunc(selectTag,selectType){
				if(selectTags==selectTag){
					for(var i=0;i<len;i++){
						if(selectType.indexOf("Ids")>0){
							var nn= $(".infoLlist .ui_checkbox").eq(i).attr("t-id");
						}else{
							var nn= $(".infoLlist .ui_checkbox").eq(i).attr("t-name");
						}
						var qc=getSs(window[selectType],nn);
						if(qc||qc==0){
							var getChannelsArr=window[selectType].split(',');
								getChannelsArr.splice(qc,1);
							window[selectType]=getChannelsArr.join(',');
						}
					}
				}
			}
			allSelectsFunc("partSelectNews","getChannels");
			allSelectsFunc("partFilterNews","notChannels");
			allSelectsFunc("partSelectWeChat","getWechatIds");
			allSelectsFunc("partFilterWeChat","notWechatIds");
			allSelectsFunc("partSelectWeibo","getBloggerIds");
			allSelectsFunc("partFilterWeibo","notBloggerIds");
			allSelectsFunc("partSelectBBS","getBbsNames");
			allSelectsFunc("partFilterBBS","notBbsNames");

		}
	});
	//只要有选项没被选中，那么全选就不会出现选中状态
	$(".infoLlist .ui_checkbox").live("click", function() {
		checkTrueFalse();
	});

	function checkTrueFalse() {
		var isTrue = "true";
		$(".infoLlist .ui_checkbox").each(function() {
			var checkedbtn = $(this).attr("checkedbtn");
			if(checkedbtn == "false") {
				isTrue = "false";
				return;
			}
		});
		if(isTrue == "false") {
			$(".selectAllAreaGoGo .allSel").removeClass("checked").attr("checkedbtn", "false");
		} else {
			$(".selectAllAreaGoGo .allSel").addClass("checked").attr("checkedbtn", "true");
		}
	}

	//点击查询
	$("#checkQueryBtn").live("click", function() {
		curPage = 1;
		qDataFun(curPage);
	});
	$('.enterKeyDownElement').keydown(function(e) {
		if(e.keyCode == 13) {
			curPage = 1;
			qDataFun(1);
		}
	});
	//点击触发换页的按钮
	$("#pageArea .pNumBtn  a").live("click", function() {
		curPage = parseInt($(this).attr("toPage"));
		qDataFun(curPage);
	});

	//点击触发分批显示的按钮
	$("#pageArea .columnsPage a").live("click", function() {
		numList = parseInt($(this).text());
		curPage = 1;
		qDataFun(curPage);
		subPage = $(this).index();
	});
	//跳转
	$("#pageArea .gopg .btn").live("click", function() {
		curPage = parseInt($("#pageArea .gopg .txt").val());
		//判断输入的页数是否大于最大的页数
		if(curPage>countPage){
			curPage=countPage;
		}
		if(curPage>0){
			qDataFun(curPage);
		}
	});

	function qDataFun(curPages) {
		channel_name_text = $("#checkQueryInput").val();
		weixin_name_text = $("#checkQueryInput").val();
		microuser_blogger_text = $("#checkQueryInput").val();
		selectJsonData = null;
		selectJsonData = {
			channel_name: channel_name_text,
			weixin_name: weixin_name_text,
			microuser_blogger: microuser_blogger_text
		};
		var rscArr2 =  $(".cL").parent().prev().text().split(",");
		var params={};
		edit.qRscList($(".cL"), rscArr2, params, curPages, numList, selectJsonData);
	};
});

